import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
//导入axios插件
import axios from "axios";
//axios基础路径
axios.defaults.baseURL="http://localhost:7000"
//axios的请求拦截器
axios.interceptors.request.use(config=>{
    //判断是否登录
    var token = sessionStorage.getItem("token");
    if(token){
        config.headers.token=token;
    }
    return config;
})

//挂载axios到vue对象上
Vue.prototype.$http=axios;
Vue.config.productionTip = false
//前置路由守卫。to  from
router.beforeEach((to,from,next)=>{
      var path = to.path;
      if(path==="/login"){
           return next();
      }
      //判断是否登录
      var token = sessionStorage.getItem("token");
      if(token){
          return next();
      }
      return next("/login");
})






new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
